package com.ironman.common.util;

import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class GpsUtil {

    /**
     * 60进制 转 10进制
     */
    public static Double binaryConversion(String base60, int index) {
        if (StrUtil.isBlank(base60)) {
            return null;
        }
        // 3158.08744,N,12055.50737,E
        return NumberUtil.round(Float.parseFloat(base60.substring(0, base60.length() - index)) + NumberUtil.div(Float.parseFloat(base60.substring(base60.length() - index)), 60), 6).doubleValue();
    }

    public static void main(String[] args) {
        // 纬度
        String latitudeStr = "3158.06186";
        // 经度
        String longitudeStr = "12055.41916";
        //120.923653,31.967698
        System.out.println(GpsUtil.binaryConversion(longitudeStr, 8) + "," + GpsUtil.binaryConversion(latitudeStr, 8));
    }
}